<template>
  <div>
   <el-form :model="pubhie" ref="pwdFormRef" label-width="100px">
    <el-form-item label="排序">
      <el-input v-model="pubhie.order"></el-input>
    </el-form-item>
     <el-form-item label="角色名称">
      <el-input v-model="pubhie.name"></el-input>
    </el-form-item>
      <el-form-item label="角色描述">
      <el-input v-model="pubhie.desc"></el-input>
    </el-form-item>
   </el-form>
    <div slot="footer" class="dialog-footer">
    <el-button size="small" @click="quxiao">取 消</el-button>
    <el-button size="small" type="primary" @click="queding">确 定</el-button>
  </div>
  </div>
</template>

<script>
import {addracter,compileracter} from '@/api/limits'
export default {
  props:{
       childata:{
       type: Object,
      require: true
    },
     isedite: {
      type: Boolean,
      required: true
    },
  },
data () {
  return {
    pubhie:{
      order:'',
      name:'',
      desc:''
    }
  }
},
created(){
  this.loadingche()
},
methods:{
  loadingche(){
    if(this.isedite==true){
      this.pubhie = this.childata
      console.log(this.childata);
    } else{
      return
    }
  },
    // 取消
  quxiao(){
    this.$emit('close')
  },
  // 确定
 async queding(){
  if(this.isedite == true){
   const resc = await compileracter(this.pubhie)
   this.$message.success(resc.msg)
    this.$refs.pwdFormRef.resetFields()

  } else{
    const res = await addracter(this.pubhie)
       this.$message.success(res.msg)
    console.log(res);
    this.$refs.pwdFormRef.resetFields()
  }
    this.$emit('close')
     
  }
}
}
</script>

<style scoped>
.dialog-footer{
 width: 45%;
 margin-left: 60%;
 margin-top: 20px;
}
.el-form{
  margin-right: 32px;
}
</style>